9638. Easy problem for Dino

 

Given two different integers a and b. Find such integer k that |a – k| = |b – k|.

Note: |x| means the absolute value of x.

 

Input. Two integers a and b (-109 a, b 109, a b).

 

Output. If the value of k doesn’t exist, print “-”. Otherwise print k.

 

Sample input 1

Sample output 1

10 5

-

 

 

Sample input 2

Sample output 2

6 2

4

 

 

SOLUTION

mathematics

 

Algorithm analysis

The equation |a – k| = |b – k| is equivalent to one of the following:

·        a – k = b – k or a = b, which is impossible because a b;

·        a – k = k – b or 2k = a + b, k = (a + b) / 2;

The solution exists if a + b is divisible by 2.

 

Example

In the second test we have the equation: |6 – k| = |2 – k|, wherefrom

6 – k = k – 2, 2k = 8, k = 4

 

Algorithm realization

Read the input data.

 

scanf("%lld %lld", &a, &b);

 

If a + b is not divisible by 2, then there is no solution. Otherwise the answer is (a + b) / 2.

 

c = a + b;

if (c % 2 != 0) printf("-\n");

else printf("%lld\n", c / 2);